<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Block本质</title>
  
  <link href="../css/semantic/semantic.min.css" rel="stylesheet">
  <link href="../css/markdown.css" rel="stylesheet">
  <link href="../css/wtxynavigation.css" rel="stylesheet">
  <script src="../js/jquery.min.js"></script>
  <script type="text/javascript" src="../js/include.js"></script>

  <style>
    body{padding-top:0;background:#f7f7f7}
    body>.ui.container{width:100%;padding:0}
    #project-title{background:#6e6e6e;width:100%;line-height:3.572rem;color:#fff;font-size:1.2rem}
    #project-title .title-wrap{font-weight:700;padding:0 12px;width:100%;max-width:1366px!important;min-width:900px;margin:0 auto}
    #project-title .left,#project-title right{display:inline-block}
    #project-title .right{float:right}
    #project-title .right .wiki-actions .menu{left:auto;right:0;margin-top:.4em!important}
    #wiki-preview-container{width:100%;max-width:1366px!important;min-width:900px;padding:0;border:1px solid #e3e9ed;border-top:0}
    #wiki-preview>.ui.segment{margin-top:0;padding:1rem;padding-left:0;border:0}
    .hover-places{display:inline-block}
    #page-detail{width:60%;margin:0 auto}
    #page-detail .title{font-weight:700;font-size:24px;padding:12px 0;border-bottom:1px solid #ccc}
    #page-detail .content{margin-top:15px}
    .content p{word-wrap:break-word}
    #wiki-parent,#wiki-title,#wikis{display:none}
    .ui.grid{padding:0!important}
    #ex-all{cursor:pointer;color:#537c8d}
  </style>
</head>
<body>
  <div class="ui container">
    <div id="project-title">
      <div class="title-wrap">
        <div class="left">
          <i class="icon eye"></i>
          文档预览:
          mianmSDK
        </div>
        <div class="right">
          Export by Gitee
        </div>
      </div>
    </div>

    <div class="ui container" id="wiki-preview-container">
      <div id="wiki-preview">
        <div class="ui segment">
          <div id="page-detail" class="markdown-body">
            <div class='title'>37.Block本质</div><div class='content'><h1>
<a id="block本质" class="anchor" href="#block%E6%9C%AC%E8%B4%A8"></a>Block本质</h1>
<p><strong>关键词</strong>: <code>Block</code>,<code>截获变量</code>,<code>__block</code>,<code>内存管理</code>,<code>栈</code>,<code>堆</code>,<code>执行上下文</code>,<code>函数</code></p>
<h1>
<a id="说不定会问下面的问题总览" class="anchor" href="#%E8%AF%B4%E4%B8%8D%E5%AE%9A%E4%BC%9A%E9%97%AE%E4%B8%8B%E9%9D%A2%E7%9A%84%E9%97%AE%E9%A2%98%E6%80%BB%E8%A7%88"></a>说不定会问下面的问题(总览)</h1>
<h2>
<a id="block介绍" class="anchor" href="#block%E4%BB%8B%E7%BB%8D"></a>Block介绍</h2>
<p>什么是Block, 你对Block的调用是怎样理解的?</p>
<h2>
<a id="截获变量" class="anchor" href="#%E6%88%AA%E8%8E%B7%E5%8F%98%E9%87%8F"></a>截获变量</h2>
<p>系统关于block截获变量是怎样实现的?</p>
<h2>
<a id="__block修饰符" class="anchor" href="#__block%E4%BF%AE%E9%A5%B0%E7%AC%A6"></a><code>__block</code>修饰符</h2>
<p>对一些变量用<code>__block</code>修饰符, 是用来做什么的?</p>
<h2>
<a id="block的内存管理" class="anchor" href="#block%E7%9A%84%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86"></a>block的内存管理</h2>
<p>我们什么时候需要对Block进行copy操作?
栈和堆Block你是否了解?</p>
<h2>
<a id="block的循环引用" class="anchor" href="#block%E7%9A%84%E5%BE%AA%E7%8E%AF%E5%BC%95%E7%94%A8"></a>Block的循环引用</h2>
<h1>
<a id="什么是block" class="anchor" href="#%E4%BB%80%E4%B9%88%E6%98%AFblock"></a>什么是Block?</h1>
<h1>
<a id="答--block是将函数及其执行上下文封装起来的对象" class="anchor" href="#%E7%AD%94--block%E6%98%AF%E5%B0%86%E5%87%BD%E6%95%B0%E5%8F%8A%E5%85%B6%E6%89%A7%E8%A1%8C%E4%B8%8A%E4%B8%8B%E6%96%87%E5%B0%81%E8%A3%85%E8%B5%B7%E6%9D%A5%E7%9A%84%E5%AF%B9%E8%B1%A1"></a>答:  Block是将函数及其执行上下文封装起来的对象.</h1>
<h1>
<a id="详解" class="anchor" href="#%E8%AF%A6%E8%A7%A3"></a>详解</h1>
<h1>
<a id="1-编译一个m" class="anchor" href="#1-%E7%BC%96%E8%AF%91%E4%B8%80%E4%B8%AAm"></a>1. 编译一个.m</h1>
<pre><code>
clang -rewrite-objc MyBlock.m

</code></pre>
<p><a href="https://gitee.com/wutongxd/QuestionsAndAnswersPro/tree/master/9.Block/study">具体看代码</a></p>
<h2>
<a id="总结" class="anchor" href="#%E6%80%BB%E7%BB%93"></a>总结:</h2>
<ol>
<li>Block 就是一个对象</li>
<li>这个对象封装了, <strong>函数</strong>以及<strong>函数的执行上下文</strong>
</li>
</ol>
<h1>
<a id="什么是block调用" class="anchor" href="#%E4%BB%80%E4%B9%88%E6%98%AFblock%E8%B0%83%E7%94%A8"></a>什么是Block调用?</h1>
<ol>
<li>
<strong>Block</strong>调用就是<strong>函数的调用</strong>
</li>
</ol></div>
          </div>
        </div>
      </div>
      </div>
  </div>
</body>
</html>